from app import db
from .teacher import Teacher


class Course(db.Model):

    __tablename__ = 'tbl_course'

    Cos_id = db.Column(db.String(10), primary_key=True)
    Cos_name = db.Column(db.String(50), nullable=False)
    Cos_credit = db.Column(db.Float, nullable=True)
    Cos_teacher = db.Column(db.String(10), nullable=True)
    Cos_intro = db.Column(db.String)
    Cos_time = db.Column(db.String(50), nullable=True)
    Cos_site = db.Column(db.String(50), nullable=True)
    Cos_college = db.Column(db.String(50), nullable=True)
    Cos_stime = db.Column(db.DateTime(), nullable=True)
    Cos_etime = db.Column(db.DateTime(), nullable=True)
    Cos_maxNum = db.Column(db.Integer, nullable=True)
    Cos_num = db.Column(db.Integer, nullable=True)
    Cos_selectable = db.Column(db.SmallInteger, nullable=False)

    def to_json(self):
        return {
            'Cos_id': self.Cos_id,
            'Cos_name': self.Cos_name,
            'Cos_credit': self.Cos_credit,
            'Cos_teacher': self.Cos_teacher,
            'Cos_intro': self.Cos_intro,
            'Cos_time': self.Cos_time,
            'Cos_site': self.Cos_site,
            'Cos_college': self.Cos_college,
            'Cos_stime': str(self.Cos_stime),
            'Cos_etime': str(self.Cos_etime),
            'Cos_maxNum': self.Cos_maxNum,
            'Cos_num': self.Cos_num,
            'Cos_selectable': self.Cos_selectable
        }